{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f93952a4-c48c-4bfe-8305-00fb7093fe6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入字符串： i am a fuck bi aq  qqfqf  qfqfq  q q q \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "其中的单词总数有： 11\n"
     ]
    }
   ],
   "source": [
    "Number = 0   #统计单词个数\n",
    "word = False #判断是否是单词\n",
    "strs=input(\"请输入字符串：\")\n",
    "for i in range(len(strs)):\n",
    "    ch=strs[i]\n",
    "    if (ch == ' '): word = False\n",
    "    elif (not word):\n",
    "        word = True; Number+=1\n",
    "#print(\"字符串为：\", strs);\n",
    "print(\"其中的单词总数有：\", Number)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dddb3a7b-13de-4c04-8c59-d9da586cff7e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "476b0cb0-d60b-4520-8e95-1f03603e53a0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
